﻿

using Prism.Ioc;
using Prism.Services.Dialogs;
using System.Xml.Linq;
using System;
using DualPlaneFR4Paster.Models;
using Prism.Commands;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace DualPlaneFR4Paster.ViewModels.Dialogs
{
    public class MessageBoxDialogViewModel : DialogViewModel
    {
        #region 属性
        private string cancelButtonVisibility;
        public string CancelButtonVisibility
        {
            get { return cancelButtonVisibility; }
            set { SetProperty(ref cancelButtonVisibility, value); }
        }
        private string msgContain;
        public string MsgContain
        {
            get { return msgContain; }
            set { SetProperty(ref msgContain, value); }
        }
        private ImageSource iconSoucePath;
        public ImageSource IconSoucePath
        {
            get { return iconSoucePath; }
            set { SetProperty(ref iconSoucePath, value); }
        }
        #endregion
        #region 命令
        private DelegateCommand<object> operateCommad;
        public DelegateCommand<object> OperateCommad =>
            operateCommad ?? (operateCommad = new DelegateCommand<object>(ExecuteOperateCommad));

        void ExecuteOperateCommad(object obj)
        {
            switch (obj.ToString())
            {
                case "确认":
                    OnRequestClose(new DialogResult(ButtonResult.Yes));
                    break;
                case "取消":
                    OnRequestClose(new DialogResult(ButtonResult.No));
                    break;
                default:
                    break;
            }
        }
        #endregion
        public override void OnDialogOpened(IDialogParameters parameters)
        {
            var messageType = parameters.GetValue<MessageType>("MessageType");
            switch (messageType)
            {
                case MessageType.Message:
                    {
                        CancelButtonVisibility = "Collapsed";
                        Uri iconUri = new Uri("pack://application:,,,/Views/Resources/information.ico", UriKind.RelativeOrAbsolute);
                        IconSoucePath = BitmapFrame.Create(iconUri);
                    }
                    break;
                case MessageType.Confirm:
                    {
                        CancelButtonVisibility = "Visible";
                        Uri iconUri = new Uri("pack://application:,,,/Views/Resources/warning.ico", UriKind.RelativeOrAbsolute);
                        IconSoucePath = BitmapFrame.Create(iconUri);
                    }
                    break;
                default:
                    break;
            }
            Title = parameters.GetValue<string>("MsgCaption");
            MsgContain = parameters.GetValue<string>("MsgContain");
        }
        public MessageBoxDialogViewModel(IContainerProvider containerProvider) : base(containerProvider)
        {

        }
    }
}
